package com.classroom.smart.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@PropertySource("classpath:redis.properties")
public class RedisConfig {

    @Bean
    public JedisPool jedisPool(
            @Value("${redis.maxIdle}") Integer maxIdle,
            @Value("${redis.minIdle}") Integer minIdle,
            @Value("${redis.maxTotal}") Integer maxTotal,
            @Value("${redis.url}") String url,
            @Value("${redis.port}") Integer port,
            @Value("${redis.password}") String password,
            @Value("${redis.timeout}") Integer timeout
    ){
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(maxIdle);
        config.setMinIdle(minIdle);
        config.setMaxTotal(maxTotal);
        config.setBlockWhenExhausted(true);
        config.setTestOnReturn(true);
        config.setTestOnReturn(true);

        return new JedisPool(config,url,port,timeout,password);
    }
}
